<template>
  <div class="list-table">
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('项目类型')" prop="businessType">
        <el-select v-model="queryParams.businessType" :placeholder="$t('项目类型')" clearable>
          <el-option
            v-for="dict in businessTypeOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('项目名称')" prop="businessName">
        <MainBodySelect
          v-model="queryParams.serviceId"
          :parameters="queryParams.businessType"
        />
      </el-form-item>
      <el-form-item :label="$t('会议类型')" prop="meetingType">
        <el-select v-model="queryParams.meetingType" :placeholder="$t('会议类型')" clearable>
          <el-option
            v-for="dict in meetingTypeOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('申请时间')" prop="applyTime">
        <DatePicker
          v-model="queryParams.applyTime"
          :placeholder="$t('申请时间')"
        />

      </el-form-item>
      <el-form-item :label="$t('申请人')" prop="applicant">
        <el-input
          v-model="queryParams.applicant"
          :placeholder="$t('申请人')"
          clearable
          @keyup.enter.native="queryHandle"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['oa:business:edit']"
          type="success"
          icon="el-icon-position"
          size="mini"
          :disabled="isDisabled"
          @click="push()"
        >{{ $t('发起会议') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="mtBusinessDetailList" border @select="checkBoxSelect" @select-all="checkBoxSelect">
      <el-table-column
        type="selection"
        width="55"
        align="center"
      />
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('业务名称')" align="left" prop="serviceName" min-width="200" show-overflow-tooltip />
      <el-table-column :label="$t('业务类型')" align="center" prop="businessType" :formatter="businessTypeFormat" width="120" />
      <el-table-column :label="$t('会议类型')" align="center" prop="meetingType" :formatter="meetingTypeFormat" width="120" />
      <el-table-column :label="$t('会议轮次')" align="center" prop="meetingRounds" width="120" />
      <el-table-column :label="$t('申请时间')" align="center" prop="applyTime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.applyTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('申请人')" align="center" prop="applicantName" width="120" />

      <el-table-column fixed="right" :label="$t('申请单')" align="center" class-name="small-padding fixed-width" width="200">
        <template v-if="scope.row.dataActId !== null" slot-scope="scope">
          <el-button
            v-hasPermi="['oa:business:edit']"
            size="small"
            type="text"
            icon="el-icon-eye"
            @click="openActForm(scope.row)"
          >{{ $t('查看') }}</el-button>
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog :visible.sync="actFormOpen" :title="$t('流程详情')" :destroy-on-close="true" custom-class="dialogForm" style=" text-align: left;" append-to-body :close-on-click-modal="false" :lock-scroll="false">
      <ProcessInfoForm ref="processInfoForm" />
    </el-dialog>
  </div>
</template>

<script>
import { findByBusinessIdIsNull } from '@/api/oa/business/mtBusiness'
import ProcessInfoForm from '@/views/act/process/processInfoForm'
import MainBodySelect from '@/components/MainBodySelect/index'
export default {
    components: {
      ProcessInfoForm,
      MainBodySelect
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 流程表单是否展示
          actFormOpen: false,
          // 总条数
          total: 0,
          // 上会项目表格数据
          mtBusinessDetailList: [],
          // 弹出层标题
          title: '',
          isDisabled: true,
          // 是否显示弹出层
          formOpen: false,
          // 业务类型 字典my_business_type字典
          businessTypeOptions: [],
          // 会议类型 字典mt_type字典
          meetingTypeOptions: [],
          // 查询参数
          queryParams: {
              businessType: undefined,
              serviceId: undefined,
              meetingType: undefined,
              meetingRounds: undefined,
              applyTime: undefined,
              applicant: undefined,
              applyForm: undefined,
              pageNum: 1,
              pageSize: 10
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {
          }
      }
  },
  created() {
      this.getList()
      this.getDicts('my_business_type').then(response => {
          this.businessTypeOptions = response.data
      })
      this.getDicts('mt_type').then(response => {
          this.meetingTypeOptions = response.data
      })
  },
  methods: {
    /** 查询上会项目列表 */
    getList() {
        this.loading = true
        findByBusinessIdIsNull(this.queryParams).then(response => {
            this.mtBusinessDetailList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    // 业务类型 字典my_business_type字典翻译
    // eslint-disable-next-line no-unused-vars
    businessTypeFormat(row, column) {
      return this.selectDictLabel(this.businessTypeOptions, row.businessType)
    },
    // 会议类型 字典mt_type字典翻译
    // eslint-disable-next-line no-unused-vars
    meetingTypeFormat(row, column) {
      return this.selectDictLabel(this.meetingTypeOptions, row.meetingType)
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            businessType: undefined,
            businessName: undefined,
            meetingType: undefined,
            meetingRounds: undefined,
            applyTime: undefined,
            applicant: undefined,
            applyForm: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.title = '添加上会项目'
        this.$nextTick(() => {
            this.$refs.mtBusinessDetailForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.title = '修改上会项目'
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.mtBusinessDetailForm.init(row)
        })
    },
    /** 推送按钮操作 */
    push() {
        this.$emit('push')
    },
    checkBoxSelect(row) {
      this.isDisabled = row.length <= 0
      this.$emit('getBusinessDetailIds', row)
    },
    // 查看流程申请单
    openActForm(row) {
      this.actFormOpen = true
      this.$nextTick(() => {
        var proData = {}
        proData.actId = row.dataActId
        this.$refs.processInfoForm.init(proData)
      })
    }
  }
}
</script>
